package com.hospital.job.config.data;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

@Data
@ConfigurationProperties("xxl.job")
@Validated
public class XxlJobProperty {

    private Boolean enabled=true;
    private String accessToken;
    @NotNull(message = "控制器配置不能为空")
    private AdminProperty admin;
    @NotNull(message = "执行器配置不能为空")
    private ExecutorProperty executor;

    @Data
    @Valid
    public static class AdminProperty{
        @NotNull(message = "调度器地址不能为空")
        private String addresses;
    }

    @Data
    @Valid
    public static class ExecutorProperty{
        private static final Integer PORT_DEFAULT=-1;

        private static final Integer LOG_RETENTION_DAYS_DEFAULT=30;

        @NotEmpty(message = "应用名不能为空")
        private String appName;
        private String ip;
        private Integer port=PORT_DEFAULT;
        @NotEmpty(message = "日志地址不能为空")
        private String logPath;
        private Integer logRetentionDays=LOG_RETENTION_DAYS_DEFAULT;
    }
}
